<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        .cover{
            display: none;
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            place-items: center;
            background-color: rgba(0,0,0,0.5);
            animation: show 2s linear;
	        -webkit-animation: show 2s linear; /*Safari and Chrome*/
        }

        @keyframes show
        {
            from {
                display: none;
                background-color: rgba(0,0,0,0);
            }
            to {
                display: grid;
                background-color: rgba(0,0,0,0.5);
            }
        }

        @-webkit-keyframes show /*Safari and Chrome*/
        {
            from {
                display: none;
                background-color: rgba(0,0,0,0);
            }
            to {
                display: grid;
                background-color: rgba(0,0,0,0.5);
            }
        }

        .box{
            width: 100px;
            height: 100px;
            display: grid;
            place-items: center;
            background-color: cornflowerblue;
        }

    </style>
    
    <script>
        function showCover(){
            const cover = document.getElementById("cover")

            cover.style.display = cover.style.display === "grid"?"none":"grid"
        }
    </script>
</head>
<body>

    <button onclick="showCover()">显示弹窗</button>
    <div id="cover" class="cover">
        <div class="box">
            我是弹框
        </div>
    </div>

</body>
</html>